<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'app',
  data () {
    return {
      res: {}
    };
  },
  mounted () {
    if (this.$cookie.get('userId')) {
      this.getUser();
      this.getCartCount();
    }
  },
  methods: {
    getUser () {
      this.axios.get('/user').then((res = {}) => {
        this.$store.dispatch('saveUserName', res.username)
      });
    },
    getCartCount () {
      this.axios.get('/carts/products/sum').then((res = 0) => {
        this.$store.dispatch('saveCartCount', res);
      });
    }
  }
}
</script>

<style lang="stylus">
@import './assets/stylus/reset.styl';
@import './assets/stylus/config.styl';
@import './assets/stylus/button.styl';
</style>
